import * as mobx from 'mobx';
const observable = mobx.observable;
const action = mobx.action;
import { WeaTableNew, WeaForm } from 'comsMobx';
const { TableStore } = WeaTableNew;
import * as API_SUB_WORKFLOW_STATUS from '../apis/subWorkflowStatus';
import { WeaTools ,WeaLocaleProvider} from 'ecCom';
import { ListStore } from './listStore';

import {message} from 'antd';
const getLabel = WeaLocaleProvider.getLabel;


export class SubWorkflowStatusStore{

  urlParams = {};//url请求参数

  @observable loading = false;
  title = "";
  @observable tableStore = new TableStore();

  /** 高级查询store */
  @observable form = new WeaForm();
  @observable showSearchAd = false;
  condition = [];
  


  constructor(){
    this.init = this.init.bind(this);
    this.getSessionkey = this.getSessionkey.bind(this);
    this.getConditionInfo = this.getConditionInfo.bind(this);
    this.setShowSearchAd = this.setShowSearchAd.bind(this);
    this.clearStatus = this.clearStatus.bind(this);
  }

  setShowSearchAd(bool) {
    this.showSearchAd = bool;
  }

  @action('初始化')
  init(urlParams = {}){
    this.urlParams = urlParams;
    this.getConditionInfo();
    this.getSessionkey();
  }


  @action('列表')
  getSessionkey(params={}){
    this.loading = true;
    this.tableStore.setSelectedRowKeys([]);
    const formParams = this.form.getFormParams();
    API_SUB_WORKFLOW_STATUS.getSessionkey({...formParams,...params,...this.urlParams}).then((data)=>{
      this.tableStore.getDatas(data.sessionkey, params.current || 1);
      this.title = data.title;
      this.loading = false;
    });
  }

  @action('高级查询form信息')
  getConditionInfo(params={}){
    this.setShowSearchAd(false);
    API_SUB_WORKFLOW_STATUS.getConditionInfo().then((data)=>{
        let condition = data.conditioninfo;
        this.condition = condition;
        this.form.initFormFields(condition);
    });
  }

  clearFormFields = ()=>{
    this.form.resetConditionValue();      //清除查询条件值
  }

  appendFormFields = (value)=>{
    this.form.updateFields(value, false);
  }

  @action('清除整个组件的状态')
  clearStatus(){
    this.showSearchAd = false;
    this.selectedTreeKey = "";
    this.clearFormFields();
  }

}
